import { useEffect, useState } from 'react'

// 注意格式，useXxx
export const useMouse = () => {
  const [pos, setPos] = useState({
    x: 0,
    y: 0,
  })
  useEffect(() => {
    // 副作用处理函数
    const mousemove = (e) => {
      console.log('~~')
      setPos({
        x: e.pageX,
        y: e.pageY,
      })
    }
    document.addEventListener('mousemove', mousemove)
    return () => {
      // 清理函数
      document.removeEventListener('mousemove', mousemove)
    }
  }, [])
  return pos
}
